<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        window.onload = initAll;

        function initAll() {
            var ans = prompt("Enter a number", "");
            try {
                if (!ans || isNaN(ans) || ans < 0) {
                    //抛出一个错误，指出“Not a number,代码直接调转到catch并输出错误信息
                    throw new Error("not a number");
                }
                alert("the square root of" + ans + "is" + Math.sqrt(ans))
            } catch (error) {
                alert(error.message)
            }
        }
    </script>
</body>

</html>